package controller.comparator;

import java.util.*;

import entity.Bid;

/**
 * Compares Bid object by
 * <ol>
 * <li>Alphabetical order of course code</li>
 * <li>Descending order of bid amount</li>
 * <li>Alphabetical order of user id</li>
 * </ol>
 * 
 * @author jaslin.wee.2012, huiwensong.2012
 */

public class BidComparatorByBidAmountAndUserId implements Comparator<Bid> {

	@Override
	public int compare(Bid bid, Bid anotherBid) {
		
		/*
		 * Compare bid amount in descending order
		 */
		int k = Double.compare(bid.getBidAmount(), anotherBid.getBidAmount());
		k *= -1;
		if(k != 0){
			return k;
		}
		
		/*
		 * Compare user id in ascending order
		 */
		String userId = bid.getStudent().getUserId();
		String anotherUserId = anotherBid.getStudent().getUserId();
		k =  userId.compareToIgnoreCase(anotherUserId);
		return k;
		
		
		
	}

}
